﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zor_DAL;
using Zor_Tools;

namespace Zor_Bll
{
    public class PayTaxesBrowse_Bll<T> where T : class
    {
        /// <summary>
        /// 获取税收信息列表
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="TotalCount">返回值</param>
        /// <returns></returns>
        /// 
        public static List<T> GetPageList(dynamic Model, int index, out int TotalCount,string where)
        {

            int Dtid = RequestSession.GetSessionUser().DT_Id;
            int Isadmin = RequestSession.GetSessionUser().Is_Admin;
            var sqlSurch = " 1=1 ";
            if (Isadmin == 1 || Dtid == 16)
            {
                sqlSurch = " 1=1 ";
            }
            else
            {
                sqlSurch = "( StreetOfficeID = " + Dtid + " or Dt_ParentId = " + Dtid + " )";
            }
            if (Model.StreetOffice != null)
            {
                sqlSurch += " and " + " StreetOffice like '%" + Model.StreetOffice + "%'  ";
            }
            if (Model.Community != null)
            {
                sqlSurch += " and " + " Community like '%" + Model.Community + "%'  ";
            }
            if (Model.NatPer_Name != null)
            {
                sqlSurch += " and " + " NatPer_Name like '%" + Model.NatPer_Name + "%'  ";
            }
            if (Model.Tenant_Name != null)
            {
                sqlSurch += " and " + " Tenant_Name like '%" + Model.Tenant_Name + "%'  ";
            }
            if (Model.Acceptance_TicketNumber != null)
            {
                sqlSurch += " and " + " Acceptance_TicketNumber = '" + Model.Acceptance_TicketNumber + "'  ";
            }
            if (Model.Pt_CertificateNumber != null)
            {
                sqlSurch += " and " + " Pt_CertificateNumber = '" + Model.Pt_CertificateNumber + "'  ";
            } 
          

             if (Model.Acceptance_TaxStartTime != null && Model.Acceptance_TaxEndTime == null)
            {              
                int state = TimeHelper.ToTimeStamp(DateTime.Parse((Model.Acceptance_TaxStartTime + " 00:00:00").ToString()));
                int end = TimeHelper.ToTimeStamp(DateTime.Parse((Model.Acceptance_TaxStartTime + " 23:59:59").ToString()));              
                sqlSurch += " and " + " Pt_Date >= " + state + " and Pt_Date<= " + end + " ";
            }
            if (Model.Acceptance_TaxEndTime != null && Model.Acceptance_TaxStartTime == null)
            {
                int state = TimeHelper.ToTimeStamp(DateTime.Parse((Model.Acceptance_TaxEndTime + " 00:00:00").ToString()));
                int end = TimeHelper.ToTimeStamp(DateTime.Parse((Model.Acceptance_TaxEndTime + " 23:59:59").ToString()));
                sqlSurch += " and " + " Pt_Date >= " + state + " and Pt_Date<= " + end + " ";
            }
            if (Model.Acceptance_TaxStartTime != null && Model.Acceptance_TaxEndTime != null)
            {
                int StartTime = TimeHelper.ToTimeStamp(DateTime.Parse((Model.Acceptance_TaxStartTime + " 00:00:00").ToString()));
                int EndTime = TimeHelper.ToTimeStamp(DateTime.Parse((Model.Acceptance_TaxEndTime + " 23:59:59").ToString()));  
                //int StartTime = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Acceptance_TaxStartTime.ToString()));
                //int EndTime = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Acceptance_TaxEndTime.ToString()));
                sqlSurch += " and " + " Pt_Date >=" + StartTime + " and  Pt_Date<=" + EndTime + "";
            }


            if (Model.Review_Date != null)
            {
                int Review_Date = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Review_Date.ToString()));
                sqlSurch += " and " + " Review_Date = '" + Review_Date + "'  ";
            }
            if (Model.Evaluate_Date != null)
            {
                int Evaluate_Date = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Evaluate_Date.ToString()));
                sqlSurch += " and " + " Review_Date = '" + Evaluate_Date + "'  ";
            }
            if (Model.Examine_Date != null)
            {
                int Examine_Date = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Examine_Date.ToString()));
                sqlSurch += " and " + " Review_Date = '" + Examine_Date + "'  ";
            }
            if (Model.PtState != null)
            {
                sqlSurch += " and " + " PtState = '" + Model.PtState + "'  ";
            }
            return PagerHelp<T>.GetPagerList(index, "V_PayTaxesBrowse", "Community", out TotalCount, sqlSurch);
        }


        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="where"></param>
        /// <returns></returns>
        public static List<T> GetPayTaxesBrowseList(dynamic Model, string where)
        {
            int Dtid = RequestSession.GetSessionUser().DT_Id;
            int Isadmin = RequestSession.GetSessionUser().Is_Admin;
            var sqlSurch = " 1=1 ";
            if (Isadmin == 1 || Dtid == 16)
            {
                sqlSurch = " 1=1 ";
            }
            else
            {
                sqlSurch = "( StreetOfficeID = " + Dtid + " or Dt_ParentId = " + Dtid + " )";
            }
            if (Model.StreetOffice != null)
            {
                sqlSurch += " and " + " StreetOffice like '%" + Model.StreetOffice + "%'  ";
            }
            if (Model.Community != null)
            {
                sqlSurch += " and " + " Community like '%" + Model.Community + "%'  ";
            }
            if (Model.NatPer_Name != null)
            {
                sqlSurch += " and " + " NatPer_Name like '%" + Model.NatPer_Name + "%'  ";
            }
            if (Model.Tenant_Name != null)
            {
                sqlSurch += " and " + " Tenant_Name like '%" + Model.Tenant_Name + "%'  ";
            }
            if (Model.Acceptance_TicketNumber != null)
            {
                sqlSurch += " and " + " Acceptance_TicketNumber = '" + Model.Acceptance_TicketNumber + "'  ";
            }
            if (Model.Pt_CertificateNumber != null)
            {
                sqlSurch += " and " + " Pt_CertificateNumber = '" + Model.Pt_CertificateNumber + "'  ";
            }


            if (Model.Acceptance_TaxStartTime != null && Model.Acceptance_TaxEndTime == null)
            {
                int state = TimeHelper.ToTimeStamp(DateTime.Parse((Model.Acceptance_TaxStartTime + " 00:00:00").ToString()));
                int end = TimeHelper.ToTimeStamp(DateTime.Parse((Model.Acceptance_TaxStartTime + " 23:59:59").ToString()));
                sqlSurch += " and " + " Pt_Date >= " + state + " and Pt_Date<= " + end + " ";
            }
            if (Model.Acceptance_TaxEndTime != null && Model.Acceptance_TaxStartTime == null)
            {
                int state = TimeHelper.ToTimeStamp(DateTime.Parse((Model.Acceptance_TaxEndTime + " 00:00:00").ToString()));
                int end = TimeHelper.ToTimeStamp(DateTime.Parse((Model.Acceptance_TaxEndTime + " 23:59:59").ToString()));
                sqlSurch += " and " + " Pt_Date >= " + state + " and Pt_Date<= " + end + " ";
            }
            if (Model.Acceptance_TaxStartTime != null && Model.Acceptance_TaxEndTime != null)
            {
                int StartTime = TimeHelper.ToTimeStamp(DateTime.Parse((Model.Acceptance_TaxStartTime + " 00:00:00").ToString()));
                int EndTime = TimeHelper.ToTimeStamp(DateTime.Parse((Model.Acceptance_TaxEndTime + " 23:59:59").ToString()));  
                sqlSurch += " and " + " Pt_Date >=" + StartTime + " and  Pt_Date<=" + EndTime + "";
            }


            if (Model.Review_Date != null)
            {
                int Review_Date = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Review_Date.ToString()));
                sqlSurch += " and " + " Review_Date = '" + Review_Date + "'  ";
            }
            if (Model.Evaluate_Date != null)
            {
                int Evaluate_Date = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Evaluate_Date.ToString()));
                sqlSurch += " and " + " Review_Date = '" + Evaluate_Date + "'  ";
            }
            if (Model.Examine_Date != null)
            {
                int Examine_Date = TimeHelper.ToTimeStamp(DateTime.Parse(Model.Examine_Date.ToString()));
                sqlSurch += " and " + " Review_Date = '" + Examine_Date + "'  ";
            }
            if (Model.PtState != null)
            {
                sqlSurch += " and " + " PtState = '" + Model.PtState + "'  ";
            }
            return PayTaxesBrowse_DAL<T>.GetPayTaxesBrowseList(sqlSurch);
        }


        /// <summary>
        /// 获取社区下拉列表
        /// </summary>
        /// <returns></returns>
        public static List<T> SelectCommunity()
        {
            return PayTaxesBrowse_DAL<T>.SelectCommunity();
        }
        /// <summary>
        /// 获取下拉街道办名称
        /// </summary>
        /// <returns></returns>
        public static List<T> SelectStreetOffice()
        {
            return PayTaxesBrowse_DAL<T>.SelectStreetOffice();
        }
    }
}
